From : S.E. Morris (fish@csc.liv.ac.uk)
Subject : Implementing a map
Okay, here's is the quickest way to implement a map in Blitz...
(I'll go through it *reeeeeal* slow....) We'll do a horizontal
scroller.
First let's assume your game has more than one map. Let's assume that
is has eight levels and thus eight maps. We want to store them in
memory all at once.
Now we need to know the vertical height of the map. Let's assume
the blocks are 16x16 pixels in size and that therefore there are
16 blocks vertically down the screen.
Okay - now lets put this info together into a WORD and see what we get.
We need 3 bits to store the map number, and 4 bits to store the height.
smmmhhhh-------- ==> smmmhhhhwwwwwwww
So here is our WORD... The most-significant bit in a Blitz variable
represents the sign of the number (marked with 's' above), so we will
avoid using this as it will only lead to trouble when doing maths on
the WORD in Blitz. Next there are 3 map bits (marked as 'm') and then
there are the four height bits ('y').
This leaves us the 8 bits left over in which to represent the width...
So, our data will hold... (8 maps) x (16 blocks high) x (256 blocks wide).
Now, let's assume each entry in the map is a byte in size. So we need
8x16x256 bytes --- which is approx 32K. (I *think*!!)
If we store the data in the following order...
Map 0 : (0,0) (1,0) (2,0)....(254,0) (255,0) (0,1) (1,1) (1,2)....(254,1)
(255,1)
:
: etc. until all 16 rows of 256 bytes for map 0 have been stored.
:
Map 1 : (0,0) (1,0) (2,0)....(254,0) (255,0) (0,1) (1,1) (1,2)....(254,1)
(255,1)
:
: etc. until all 16 rows of 256 bytes for map 1 have been stored.
:
Then the we can just add our WORD containing the map/height/width to
the start address of the data to get at a particular byte.
Thus map=2,x=128,y=8 would become...
s mmm yyyy xxxxxxxx
0 010 1000 10000000 ==> 0010100010000000
Thus the byte for 2,128,8 would be found at...
offset=(m LSL 12)+(y LSL 8)+x
z=Peek.b (?my_map_data + offset)